package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.PageResponseVO;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmNewsDownOrUpDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.ChannelService;
import com.heima.wemedia.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-11-13 9:50
 */
@RestController
@RequestMapping("/api/v1/news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto){
        //1.参数校验
        dto.checkParam(); //将page size 进行范围判断，设置成合理值

        PageResponseResult pageResponseResult = newsService.findNews(dto);
        return pageResponseResult;

        //无法使用，前端确定数据处理方式
//        PageResponseVO result = newsService.findNews2(dto);
//
//        return ResponseResult.okResult(result); //{code msg data: {page size list total} }
        //{code msg data : [] page size total}
    }

    @PostMapping("/submit")
    public ResponseResult submit(@Valid @RequestBody WmNewsDto dto){

        //1.参数校验，通过注解方式解决

        newsService.submit(dto);

        return ResponseResult.okResult(null);
    }

    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@Valid @RequestBody WmNewsDownOrUpDto dto){

        newsService.downOrUp(dto);

        return ResponseResult.okResult(null);
    }
}
